<include file="Index/header" />
<body class="body">
<include file="Index/picture" />
	<div class="login_box">
	<div style="text-align:center;">
    	<p style="margin-bottom:5px;"><!-- <span style="float:none;">请填写真实的注册信息</span><br /> -->
    		<span style="float:none;">返回 <a style="float:none;" href="/Index/login?community_id={$Think.get.community_id}&invite_id={$Think.get.invite_id}">登录</a> 页</span>
    	<!-- <a href="/Index/login?community_id={$Think.get.community_id}&invite_id={$Think.get.invite_id}">直接登录</a>；第一次加入的MBA/EMBA校友请注册；非MBA/EMBA校友请勿注册。 -->
    	</p>
    </div>
    	<input type="text" id="user_phone" placeholder="手机号（必填）"/>
        <div class="count">
        	<input type="text" id="verify_code" placeholder="请输入验证码（必填）"/>
            <button type="button" onclick="getVerify();"><span id="send">发送验证码</span></button>
        </div>
        <input type="password" id="user_password" placeholder="新密码(用于客户端登录)"/>
        <input type="password" id="user_password_r" placeholder="确认新密码（必填）"/>
        <button type="button" class="submit" onclick="checkLogin()" id="tijiao">提交</button>
        <button type="button" class="submit" id="notijiao">提交中...</button>
    </div>
    <include file="Index/down" />
</body>
</html>
<script type="text/javascript">
	$(function($) {
		$("#notijiao").hide();
		$("#tijiao").show();
	});
	/*
     *验证码
     */
    function getVerify(){
        var user_phone = $("#user_phone").val();

        if(!isPhone(user_phone)){
            alert("请输入正确手机号");
            return false;
        }
        var post_data={'user_phone':user_phone,'type':2};//type=1 注册，2找回密码
        $.ajax({
            type: "POST",
            url:"/Index/getVerify",
            data: post_data,
            success: function(data){
                if(data.status == '0'){
                    alert(data.info);
                    RemainTime();
                }else{
                    alert(data.info);
                    return false;
                }

            },
            dataType:"json"
        });
        
 
    }
    function isPhone(str){
        return str.match(RegExp("^1[34578][0-9]{9}$","g"));
    }
    
    function checkPwd(str){
        return str.length > 5 && str.length<15 && !(/\s+/.test(str));
    }
    function checkVerify(str){
        return str.length==4;
    }
    var iTime = 59;
    var Account;
    function RemainTime(){
        G('send').disabled = true;
        var iSecond,sSecond="",sTime="";
        if (iTime >= 0){
            iSecond = parseInt(iTime%60);
            iMinute = parseInt(iTime/60)
            if (iSecond >= 0){
                if(iMinute>0){
                    sSecond = iMinute + "分" + iSecond + "秒";
                }else{
                    sSecond = iSecond + "秒";
                }
            }
            sTime=sSecond;
            if(iTime==0){
                clearTimeout(Account);
                sTime='发送验证码';
                iTime = 59;
                G('send').disabled = false;
            }else{
                Account = setTimeout("RemainTime()",1000);
                iTime=iTime-1;
            }
        }else{
            sTime='没有倒计时';
        }
        G('send').innerHTML = sTime;
    }
    function G(id){
        return document.getElementById(id);
    }
	function checkLogin() {
		var host = 'http://'+window.location.host;
        var user_phone = $("#user_phone").val();
        var verify_code = $("#verify_code").val();
        var user_password = $("#user_password").val();
        var user_password_r = $("#user_password_r").val();
/* console.log(content);return false; */
        
        if(!isPhone(user_phone)){
            alert("请输入正确手机号");
            return false;
        }
        if(!checkVerify(verify_code)){
            alert("验证码不正确");
            return false;
        }
        if (user_password) {
			var reg_phone = /^[A-Za-z0-9]{6,15}$/;
			if (!reg_phone.exec(user_password)) {
				alert("密码由6-20个长度的数字或字母组成！");
				return false;
			}
		}
        
        if(user_password == '' || user_password == undefined){
        	alert("密码不能为空");
			return false;
		}
        
        if(user_password != user_password_r){
        	alert("请保证两次密码填写一致");
			return false;
        }

        $("#notijiao").show();
        $("#tijiao").hide();
        var post_data={
       		'user_phone':user_phone,
       		'verify_code':verify_code,
       		'user_password':user_password,
       		'user_password_r':user_password_r
        };
        $.ajax({
            type: "POST",
            url:"/Index/findPassword",
            data: post_data,
            success: function(data){
                if(data.status == '0'){
                	//调用加入社群接口的方法
                	alert(data.info);
                	window.location.href = host+'/Index/login?community_id={$Think.get.community_id}&invite_id={$Think.get.invite_id}';
                	return false;
                }else{
                	$("#notijiao").hide();
            		$("#tijiao").show();
                	alert(data.info);
                	return false;
                }

            },
            dataType:"json"
        });
    }
</script>